  <?php require_once('inc_admin.php'); ?>

  	        <!--PAGE CONTENT -->
  	        <div id="content">

  	            <div class="inner" style="min-height:1200px;">
  	                <div class="row">
  	                    <div class="col-lg-12">


  <?php 
     require_once('inc_admin.php');
      connect();
      $sql='select vid,videoname,tid,pic,intro,uploaddate,uploadadmin,hittimes,downtimes,address from videos ';
      //echo $sql.'<br/>';
      if($_REQUEST['key'])
      {
          $key=trim($_REQUEST['key']);
          $sql.="where videoname like '%{$key}%'";    
      }
      $result=mysql_query($sql);
      $totalrows=mysql_num_rows($result);
      //获取指定的页码
      $page=$_REQUEST['page'];
      if(!isset($page))
          $page=1;
      if($_POST['search'])
          $page=1;
      //定义每页显示的行数
      $rowsperpage=4;
      //计算从表第几行开始输出
      $start=($page-1)*$rowsperpage;
      $sql.="limit {$start},{$rowsperpage}";
      $result=mysql_query($sql) or die('查询失败！'.mysql_error());
       ?>
     <center> <h3>视频信息列表</h3></center>
     <table align="center" class="table table-hover table-condensed">
     <tr class="success">
       <td align="left">
         <form  method=post action="">
           请输入视频名：
           <input type="text"  class="btn btn-default"name="key">
           <input type="submit" class="btn btn-primary" name="search" value="搜索">
         </form>
       </td>
     </tr>
       </table> 
       </form>
     <table class="table table-hover">
     <tr class="info">
         <th>视频编号</th>
         <th>视频名</th>
         <th>视频类型</th>
         <th>视频海报</th>
         <th>添加时间</th>
         <th>地址</th>
         <th>操作</th>
     </tr>
        <?php 
        while($row=mysql_fetch_assoc($result))
        {
            echo '<tr>';
            foreach ($row as $k => $value)
            {
                if($k=='tid')
                    if($value==1)
                        $value='电影 ';
                    elseif($value==2)
                        $value='电视剧';
                    elseif($value==3)
                        $value='动漫';
                    elseif($value==4)
                        $value='二次元';
                      elseif($value==5)
                        $value='搞笑';
                    elseif($value==6)
                        $value='综艺';
                    elseif($value==7)
                        $value='真人秀';
                    elseif($value==8)
                        $value='娱乐';
                    else
                        $value='不知道';
                      if($k=='pic')
                      {
                      echo '<td align="center"><img src='.videoPhotoPath.$value.' width=60 height=80 alt="海报" class="img-circle"></td>';
                      echo $value;
                    }
                      elseif($k=='hittimes'||$k=='downtimes'||$k=='uploadadmin'||$k=='intro')
                        continue;
                      else
                echo '<td>'.$value.'</td>';
            }
            
            echo '<td><a href="videoEdit.php?id='.$row['vid'].'">修改</a>|<a href="videoDelete.php?id='.$row['vid'].'" onClick="return confirm(\'确定要删除吗？\');">删除</a></td>';
            echo '</tr>';
        }
        echo '</table>';
    if ($rowsperpage>=$totalrows) 
        $totalpages=1;
     else{
       $totalpages=ceil($totalrows/$rowsperpage);
    }
    //如果不是第一页，则显示第一页和上一页的超链接，否则只显示文字
    //echo '<nav><u1 class="pager">';
    if ($page>1) {
      $first="<a href=?page=1&key={$key}>首页</a>";
      $pre="<a href=?page=".($page-1)."&key={$key}>上一页</a>";
    }else{
      $first='首页';
      $pre='上一页';
   }
   //如果不是最后一页，则显示下一页和最后一页的超链接，否则只显示文字
    if ($page<$totalpages) {
      $last="<a href=?page=$totalpages&key={$key}>尾页</a>";
      $next="<a href=?page=".($page+1)."&key={$key}>下一页</a>";
    }else{
      $last='尾页';
      $next='下一页';
    }
    echo "<table align='center'><tr>";
    echo "<td>共{$totalrows}类视频</td>";
    echo "<td>$first"."&nbsp;&nbsp;"."$pre"."&nbsp;&nbsp;";
    for($i=1;$i<=$totalpages;$i++){
      echo "<a href='?page=$i&key={$key}'>第{$i}页</a>&nbsp;&nbsp;";
    }
    echo "$next"."&nbsp;&nbsp;"."$last&nbsp;";
    //输出第几页/共几页
    echo "<font color=red>";
    echo "第".$page."页/共".$totalpages."页";
    echo "</font></td>";
    //输出转到几页的表单
    ?>
    <td >
      <form  method=post action="">
        <input type="text"  class="btn btn-default"name="page" placeholder="" size=2>
        <input type="submit"  class="btn btn-primary"value="转到">
      </form>
    </td>
                                                                                                                                      
        
       </table>
  	   

  	                    </div>
  	                </div>
                </div>
                 </div>
       
  	   <!-- FOOTER -->

  	    <!--END FOOTER -->
  	     <!-- GLOBAL SCRIPTS -->
  	    <script src="assets/plugins/jquery-2.0.3.min.js"></script>
  	     <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
  	    <script src="assets/plugins/modernizr-2.6.2-respond-1.1.0.min.js"></script>
  	    <!-- END GLOBAL SCRIPTS -->
        </body>
        </html>
